﻿using System;
using System.Diagnostics.CodeAnalysis;
using System.Security.Cryptography.X509Certificates;

public abstract class Figure
{
    public string figurename = "unkonwn";
    public abstract double getAera();
    static bool isFigure(object obj)
    {
        if (obj is Figure) 
        {
            return true;
        }
        return false;
    }
   public abstract string getFigureName();
}
public class Rectangle :Figure
{   
    protected double length;
    protected double width;
    public Rectangle()
    {
        this.length = 2;
        this.width = 1;
        figurename = "Rectangle";
    }
    public Rectangle(double length, double width)
    {
        this.length = length;
        this.width = width;
        figurename = "Rectangle";
    }
    public override double getAera()
    {
        return length*width;
    }
    public override string getFigureName()
    {
        return figurename;
    }

}
public class Square:Rectangle
{
    public Square()
    {
        length = 1;
        width = 1;
        figurename = "Square";
    }
    public Square(double length)
    {
        this.length= length;
        this.width = length;
        figurename = "Square";
    }
    public override double getAera()
    {
        return length*width;
    }
    public override string getFigureName()
    {
        return figurename;
    }
}
public class Circle : Figure
{
    protected double radius;
    protected const double PAI = 3.14;
    public Circle()
    {
        this.radius = 1;
        figurename = "Circle";
    }
    public Circle(double radius)
    {
        this.radius = radius;
        figurename = "Circle";

    }
    public override double getAera()
    {
        return PAI * radius * radius;
    }
    public override string getFigureName()
    {
        return figurename;
    }
}
public class Test
{
    static void Main(string[] args)
    {
        const int MaxFigureNum = 10;
        int figureType = 0;
        Random random = new Random();
        double sum = 0;
        for(int i = 0; i < MaxFigureNum; i++)
        {
            figureType= random.Next()%3;
            Figure figure=null;
            switch (figureType)
            {
                case 0:
                    figure= new Rectangle(); 
                    break;
                case 1:
                    figure = new Square();
                    break;
                case 2:
                    figure= new Circle();
                    break;
            }
            Console.WriteLine("This is " + figure.getFigureName());
            sum += figure.getAera();
        }
        Console.WriteLine("The sum of all graphic areas is"+sum);
    }
}